package edu.zju.gis.dldsj.service.impl;

import edu.zju.gis.dldsj.dao.RoleModelMapper;
import edu.zju.gis.dldsj.entity.RoleModel;
import edu.zju.gis.dldsj.service.RoleModelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author yanlo yanlong_lee@qq.com
 * @version 1.0 2018/08/09
 */
@Service
public class RoleModelServiceImpl implements RoleModelService {
    @Autowired
    private RoleModelMapper roleModelMapper;

    @Override
    public RoleModel select(String pk) {
        return roleModelMapper.selectByPrimaryKey(pk);
    }

    @Override
    public int insert(RoleModel roleModel) {
        return roleModelMapper.insertSelective(roleModel);
    }

    @Override
    public void update(RoleModel roleModel) {
        roleModelMapper.updateByPrimaryKeySelective(roleModel);
    }

    @Override
    public void delete(String s) {
        roleModelMapper.deleteByPrimaryKey(s);
    }

    @Override
    public boolean isExist(String s) {
        return roleModelMapper.selectByPrimaryKey(s) != null;
    }

    @Override
    public List<RoleModel> getByPage(int offset, int size) {
        return roleModelMapper.selectByPage(offset, size);
    }


    @Override
    public void insert(@NotNull List<RoleModel> models) {
        models.forEach(roleModelMapper::insertSelective);
    }

    @Override
    public void update(@NotNull List<RoleModel> models) {
        models.forEach(roleModelMapper::updateByPrimaryKeySelective);
    }

    @Override
    public void deleteByRoleId(String roleId) {
        roleModelMapper.deleteByRoleId(roleId);
    }

    @Override
    public void delete(String roleId, String modelId) {
        roleModelMapper.delete(roleId, modelId);
    }

    @Override
    public boolean exist(String roleId, String modelId) {
        return roleModelMapper.select(roleId, modelId) != null;
    }

    @Override
    public List<RoleModel> selectByRoleId(String roleId) {
        return roleModelMapper.selectByRoleId(roleId);
    }

    @Override
    public void updateStatus(String artifactId, String status) {
        roleModelMapper.updateStatus(artifactId, status);
    }
}
